package cn.chjyj.sxzsys.other;

import org.junit.Test;

import java.security.MessageDigest;
import java.util.UUID;

public class ByteYs {
    /**
     * int 类型 右移计算
     */
    @Test
    public void RightByte(){
        int ss=4992;
        System.out.println("Before>>:"+ss);
        System.out.println(Integer.toBinaryString(ss));
        ss >>= 4;
        System.out.println("After:"+ss);
        System.out.println(Integer.toBinaryString(ss));
    }

    @Test
    public void testCharByte(){
        //生成uuid
        String tkuuid= UUID.randomUUID().toString();
        //加密转化
        try {
            //md5摘要
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            // 字符转化为byte
            messageDigest.update(tkuuid.getBytes());
            byte[] nmessageDig = messageDigest.digest();
            //调用右移 、 与运算
            char[] hexcode="0123456789abcdef".toCharArray();
            StringBuilder rb = new StringBuilder(nmessageDig.length*2);
            for(byte b:nmessageDig){
                rb.append(hexcode[(b>>4) & 0xF]);
                rb.append(hexcode[(b&0xF)]);
            }
            System.out.println(rb.toString());

        }catch (Exception ex){
            // 打印出异常
            ex.printStackTrace();
        }


    }
}
